package com.oscroll.singleton.lesson;

/**
 * 防止反射侵入
 */
public class LazyThree {

    private static boolean initialized = false;
    // 默认使用lasythree的时候，默认会初始化内部类
    // 如果没有使用的话，内部类是不加载的

    private LazyThree() {
        synchronized (LazyThree.class) {
            if (!initialized) {
                initialized = !initialized;
            }else {
                throw new RuntimeException("已创建");
            }
        }
    }

    public static final LazyThree getInstance() {
        return LazyHolder.LAZY;
    }

    private static class LazyHolder {
        private static final LazyThree LAZY = new LazyThree();
    }
}
